import React from 'react';
import connect from 'react-redux/lib/connect/connect';
import {actionCreators} from '../reducer';
import Dialog from 'material-ui/Dialog/Dialog';
import DialogTitle from 'material-ui/Dialog/DialogTitle';
import DialogContent from 'material-ui/Dialog/DialogContent';
import DialogContentText from 'material-ui/Dialog/DialogContentText';
import DialogActions from 'material-ui/Dialog/DialogActions';
import Button from 'material-ui/Button/Button';

import text from '../data/text.json';

const Confirm = connect(
  ({confirm}, props)=> ({...props, confirm}),
  {...actionCreators}
)(
  (
    {
      confirm: {
        open,
        title = text['confirm-title-default'],
        message = false,
        confirmPayload,
        cancelPayload,
        target,
        openType,
        closePayload
      },
      openConfirm,
      closeConfirm,
      resolveConfirm,
      ...props
    }
  ) => (
    <Dialog
      {...props}
      open={open}
      ignoreBackdropClick
    >
      <DialogTitle>{title}</DialogTitle>
      <DialogContent>
        {message &&
        <DialogContentText>{message}</DialogContentText>}
      </DialogContent>
      <DialogActions>
        <Button
          onClick={() => {
            closeConfirm(cancelPayload)
          }}
        >{text['confirm-action-nagative']}</Button>
        <Button
          color="primary"
          onClick={() => {
            closeConfirm(confirmPayload)
          }}
        >{text['confirm-action-positive']}</Button>
      </DialogActions>
    </Dialog>
  )
)
  
export default Confirm;
